home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
151-175
/
disk_165
/
plotview
/
plot
/
plotprint.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-06
|
4KB
|
209 lines
/*
plotprint.c : Print Unix Plot files in english
By Joel Swank April, 1988
*/
#include <stdio.h>
#include <ctype.h>
/*************************************************
Parameter output routine definitions
*************************************************/
#define put_xy(x,y) printf(" %ld,%ld",x,y);
#define put_int(x) printf(" %ld",x);
#define put_txt(x) printf(" %s\n",x);
FILE *input;
short longflag;
main(argc,argv)
int argc;
char *argv[];
{
struct IntuiMessage *msg;
int cmd, i;
long x,y, r;
long x1,y1,x2,y2;
char textbuf[100], *p;
longflag = 1;
/*************************************************
Interrogate command line
*************************************************/
if (argc == 1)
{
fprintf(stderr,"Usage:plotprint [-l] plotfile\n");
exit(2);
}
while (*argv[1] == '-')
{
p = (char *) &*argv[1];
p++; /* point to the option chars */
switch (*p)
{
case 'l': /* x size value */
longflag =0;
break;
default:
fprintf(stderr,"plotprint:Invalid option %s\n",argv[1]);
exit(27);
}
argc--;
argv++;
}
if (argc == 1 || argc >2)
{
fprintf(stderr,"plotprint:Exactly One filename required\n");
exit(2);
}
if ((input = fopen(argv[1],"r")) == NULL)
{
fprintf(stderr,"plotprint: %s: open failed\n",argv[1]);
exit(3);
}
/*************************************************
MAIN printing loop
*************************************************/
while ((cmd = getc(input)) != EOF)
{
switch (cmd)
{
case 'm': /* move x,y */
(longflag) ? putchar('m') : fputs("move",stdout);
get_xy(&x,&y);
put_xy(x,y);
putchar('\n');
break;
case 'n': /* draw x,y */
(longflag) ? putchar('n') : fputs("cont",stdout);
get_xy(&x,&y);
put_xy(x,y);
putchar('\n');
break;
case 'p': /* point x,y */
(longflag) ? putchar('p') : fputs("point",stdout);
get_xy(&x,&y);
put_xy(x,y);
putchar('\n');
break;
case 'l': /* line xs,ys, xe,ye */
(longflag) ? putchar('l') : fputs("line",stdout);
get_xy(&x,&y);
put_xy(x,y);
putchar(',');
get_xy(&x,&y);
put_xy(x,y);
putchar('\n');
break;
case 'a': /* arc xc,yc, xs,ys, xe,ye */
(longflag) ? putchar('a') : fputs("arc",stdout);
get_xy(&x,&y); /* get center */
put_xy(x,y);
putchar(',');
get_xy(&x,&y); /* get start point */
put_xy(x,y);
putchar(',');
get_xy(&x,&y); /* get end point */
put_xy(x,y);
putchar('\n');
break;
case 't': /* Text string\n */
(longflag) ? putchar('t') : fputs("label",stdout);
get_txt(textbuf);
put_txt(textbuf);
break;
case 'c': /* circle xc,yc, r */
(longflag) ? putchar('c') : fputs("circle",stdout);
get_xy(&x,&y);
put_xy(x,y);
putchar(',');
get_int(&r);
put_int(r);
putchar('\n');
break;
case 'f': /* linemode string\n */
(longflag) ? putchar('f') : fputs("linemod",stdout);
get_txt(textbuf);
put_txt(textbuf);
break;
case 's': /* space xlo,ylo, xhi,yhi */
(longflag) ? putchar('s') : fputs("space",stdout);
get_xy(&x,&y);
put_xy(x,y);
putchar(',');
get_xy(&x,&y);
put_xy(x,y);
putchar('\n');
break;
case 'e': /* erase */
(longflag) ? putchar('e') : fputs("erase",stdout);
putchar('\n');
break;
default:
printf("Invalid Command character:%c\n",cmd);
}
}
}
/*************************************************
Parameter input routines
*************************************************/
/*
* input a pair of 16 bit ints, scale and clip to screen,
* and return them as longs
*
*/
get_xy(x,y)
register long *x, *y;
{
get_int(x);
get_int(y);
}
/*
* input a 16 bit int and return as a long
*/
get_int(num)
long *num;
{
register short hi, lo;
lo = getc(input);
hi = (getc(input)) << 8;
*num = (long) lo + hi;
}
/*
* input a text string delinited by newline,
* return to buffer delimited by a null.
*/
get_txt(str)
char *str;
{
register int cmd;
while ((cmd = getc(input)) != '\n')
*str++ = cmd;
*str = '\0';
}